package com.egao.common.module.student.controller;

import cn.hutool.core.util.StrUtil;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.student.entity.StudentInten;
import com.egao.common.module.student.param.SearchParam;
import com.egao.common.module.student.service.StudentIntenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "学生意向数据管理")
@RestController
@RequestMapping("${api}")
public class StudentIntenParamController extends BaseController {

    @Autowired
    private StudentIntenService studentIntenService;

    @ApiOperation("根据年份查询查询条件")
    @GetMapping("/student/inten/params/{year}")
    public JsonResult params(@PathVariable("year") Integer year) {
        List<StudentInten> list = studentIntenService.listAll(year);

        List<SearchParam> sxCountry = list.stream().filter(d -> !StrUtil.isBlank(d.getSxCountryLabel()))
                .map(d -> new SearchParam(d.getSxCountry() + "", d.getSxCountryLabel()))
                .distinct().collect(Collectors.toList());

        List<SearchParam> sxSchool = list.stream().filter(d -> !StrUtil.isBlank(d.getSxSchoolLabel()))
                .map(d -> new SearchParam(d.getSxSchool() + "", d.getSxSchoolLabel()))
                .distinct().collect(Collectors.toList());

        List<SearchParam> sxMajor = list.stream().filter(d -> !StrUtil.isBlank(d.getSxMajor()))
                .map(d -> new SearchParam(d.getSxMajor() + "", d.getSxMajor()))
                .distinct().collect(Collectors.toList());

        List<SearchParam> kgProvince = list.stream().filter(d -> !StrUtil.isBlank(d.getKgProvince()))
                .map(d -> new SearchParam(d.getKgProvince() + "", d.getKgProvince()))
                .distinct().collect(Collectors.toList());

        List<SearchParam> kgCity = list.stream().filter(d -> !StrUtil.isBlank(d.getKgCity()))
                .map(d -> new SearchParam(d.getKgCity() + "", d.getKgCity()))
                .distinct().collect(Collectors.toList());

        List<SearchParam> kySchool = list.stream().filter(d -> !StrUtil.isBlank(d.getKySchool()))
                .map(d -> new SearchParam(d.getKySchool() + "", d.getKySchool()))
                .distinct().collect(Collectors.toList());

        List<SearchParam> kyMajor = list.stream().filter(d -> !StrUtil.isBlank(d.getKyMajor()))
                .map(d -> new SearchParam(d.getKyMajor() + "", d.getKyMajor()))
                .distinct().collect(Collectors.toList());

        return JsonResult.ok().put("sxCountry", sxCountry)
                .put("sxSchool", sxSchool)
                .put("sxMajor", sxMajor)
                .put("kgProvince", kgProvince)
                .put("kgCity", kgCity)
                .put("kySchool", kySchool)
                .put("kyMajor", kyMajor);
    }
}
